# encoding:utf-8
import json
import xlwt
import os

sep = os.path.sep
filepath = 'G:\\e\\out\\out\\'
outexcelpath = 'G:\\e\\r1.xls'
pathDir = os.listdir(filepath)
book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('sheet', cell_overwrite_ok=True)
line_number = 0
for allDir in pathDir:
    apk_name = allDir[allDir.rfind(sep, 1, len(allDir) - 1) + 1:allDir.rfind('.json', 1)]
    child = os.path.join('%s//%s' % (filepath, allDir))
    if (child.endswith('json')):
        f = open(child)
        jsonfile = f.read()
        json_content = json.loads(jsonfile)
        json_dict = json_content
        # print json_dict
        temps = ''
        for k, v in json_dict.iteritems():
            if len(v) != 0:
                temps = temps + k + ','
        print apk_name
        print temps
        sheet.write(line_number, 0, apk_name)
        sheet.write(line_number, 2, temps)
        line_number += 1
book.save(outexcelpath)
